package nuig.prolog.Action;

import java.util.Map;
import nuig.prolog.userTypingFormat.Rule;

import org.apache.struts2.interceptor.SessionAware;



import com.opensymphony.xwork2.ActionSupport;

public class DefaultAction extends ActionSupport implements SessionAware {
	
	
	private Map<String, Object> session;//get session map
	private String UserTyping;
	private Rule rule;

	
	
	
	@Override
	public String execute()throws Exception  {
		if(session.get("outputMessage")==null || UserTyping==null||UserTyping.length()==0||UserTyping=="")
		{
			session.put("outputMessage", "Guess,Mary,John,Cherry,Lance,Charles who is the oldest?");
		}else {
			
			rule.DoRule(UserTyping);
			
			String outputMessage=Rule.getReturnMessage().toString();
			
			if(outputMessage==null||outputMessage.length()==0)
			{
				
				outputMessage="Sorry,there is something wrong.";
			}
			//send to page
			session.put("outputMessage", outputMessage);
		}
		
		return SUCCESS;
	}
	
	
	
	
	
	
	/**
	 * get and set
	 */


	@Override
	public void setSession(Map<String, Object> Session) {
		this.session=Session;
		
	}

	public String getUserTyping() {
		return UserTyping;
	}


	public void setUserTyping(String userTyping) {
		UserTyping = userTyping;
	}

	public Rule getRule() {
		return rule;
	}


	public void setRule(Rule rule) {
		this.rule = rule;
	}


	



	/**
	 * 
	 * end of get and set
	 */

}
